
'''
你可以使用 *args 和 **kwargs 来传递任意数量的位置参数和关键字参数，而无需在函数定义中显式指定每个参数。
'''
def func7(a, b, *args, **kwargs):
    print(f"a: {a}, b: {b}")
    print(f"args: {args}")
    print(f"kwargs: {kwargs}")

# 调用函数
func7(1, 2, 3, 4, 5, x=6, y=7)



def generic_function(*args, **kwargs):
    for arg in args:
        print(f"Positional argument: {arg}")
    for key, value in kwargs.items():
        print(f"Keyword argument: {key} = {value}")

# 调用函数
generic_function(1, 2, 3, name="Alice", age=30)



def wrapper_function(func, *args, **kwargs):
    print("Calling the function with the following arguments:")
    print(f"Positional arguments: {args}")
    print(f"Keyword arguments: {kwargs}")
    result = func(*args, **kwargs)
    print("Function called successfully.")
    return result

def add(a, b):
    return a + b

def greet(name, greeting="Hello"):
    return f"{greeting}, {name}!"

# 使用封装函数
result = wrapper_function(add, 1, 2)
print(f"Result of add: {result}")

result = wrapper_function(greet, "Alice", greeting="Hi")
print(f"Result of greet: {result}")




# 扩展函数
def original_function(a, b):
    return a + b

def extended_function(a, b, *args, **kwargs):
    result = original_function(a, b)
    if args:
        print(f"Additional positional arguments: {args}")
    if kwargs:
        print(f"Additional keyword arguments: {kwargs}")
    return result

# 调用扩展函数
result = extended_function(1, 2, 3, 4, extra="info")
print(f"Result of extended_function: {result}")